<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 300px;
            border: solid 1px black;
            margin: 0 auto;
        }

        .box ul {
            margin: 0;
            padding: 0;
            list-style: none;
            display: flex;
            background: #eee;
            height: 30px;
            line-height: 30px;
        }

        .box ul li {
            flex: 1;
            border-left: solid 1px #fff;
            border-right: solid 1px #fff;
            text-align: center;
            cursor: pointer;
        }

        .box ul li.active {
            background: red;
            color: #fff;
        }

        .box .cont > div {
            height: 270px;
            display: none;
        }

        .phone {
            background: #399;
        }

        .computer {
            background: #393;
        }

        .bike {
            background: #939;
        }
    </style>
</head>
<body>
<div class="box">
    <ul>
        <li>手机</li>
        <li>电脑</li>
        <li>自行车</li>
    </ul>
    <div class="cont">
        <div class="phone">这是手机</div>
        <div class="computer">这是电脑</div>
        <div class="bike">这是自行车</div>
    </div>
</div>
<script>
    let lis = document.querySelectorAll(".box ul > li")
    let divs = document.querySelectorAll(".cont > div")
    let index = 0
    lis[index].className = "active"
    divs[index].style.display = "block"
    for (let i = 0; i < lis.length; i++) {
        lis[i].index = i
        lis[i].onclick = function () {
            lis[index].className = ""
            divs[index].style.display = "none"
            this.className = "active"
            divs[this.index].style.display = "block"
            index = this.index
        }
    }
</script>
</body>
</html>